Content Negotiation
   HOME

TheInfoList



OR:

Content negotiation refers to mechanisms defined as a part of
HTTP The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, ...
that make it possible to serve different versions of a document (or more generally, representations of a resource) at the same
URI Uri may refer to: Places * Canton of Uri, a canton in Switzerland * Úri, a village and commune in Hungary * Uri, Iran, a village in East Azerbaijan Province * Uri, Jammu and Kashmir, a town in India * Uri (island), an island off Malakula Islan ...
, so that
user agent In computing, a user agent is any software, acting on behalf of a user, which "retrieves, renders and facilitates end-user interaction with Web content". A user agent is therefore a special kind of software agent. Some prominent examples of us ...
s can specify which version fits their capabilities the best. One classical use of this mechanism is to serve an image in GIF or PNG format, so that a browser that cannot display PNG images (e.g. MS Internet Explorer 4) will be served the GIF version. A resource may be available in several different representations; for example, it might be available in different languages or different media types. One way of selecting the most appropriate choice is to give the user an index page and let them select the most appropriate choice; however it is often possible to automate the choice based on some selection criteria.


Mechanisms

HTTP provides for several different content negotiation mechanisms including: server-driven (or proactive), agent-driven (or reactive), transparent, and/or hybrid combinations thereof.


Server-driven

Server-driven or proactive content negotiation is performed by algorithms on the server which choose among the possible variant representations. This is commonly performed based on user agent-provided acceptance criteria. To summarize how this works, when a user agent submits a request to a server, the user agent informs the server what media types or other aspects of content presentation it understands with ratings of how well it understands them. More precisely, the user agent provides
HTTP header The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, w ...
s that lists acceptable aspects of the resource and quality factors for them. The server is then able to supply the version of the resource that best fits the user agent's needs. For example, a browser could indicate that it would like information in German by setting the Accept-Language like this: Accept-Language: de The browser may instead say that German is preferred, if possible, but that English is also acceptable by setting: Accept-Language: de; q=1.0, en; q=0.5 Where the 'q' - quality - factor for German is higher than that for English. Multiple HTTP headers are often supplied together for content format or, specifically media type, language and a few other aspects of a resource. In addition to the commonly used Accept header for Media Type, the Accept-Language header for language negotiation, RFC 7231 also describes Accept-Charset & Accept-Encodings for character encodings and content codings (compression) respectively. An example of a more complex request is where a browser sends headers about language indicating German is preferred but that English is acceptable, as above, and that, regarding formats,
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaSc ...
(text/html) is preferred over other text types (text/*), GIF (image/gif) or
JPEG JPEG ( ) is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and imag ...
(image/jpg) images are preferred over other image formats (image/*) but that any other media type (*/*) is accepted as a last resort: Accept-Language: de; q=1.0, en; q=0.5 Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1 In addition to aspects of server-driven content negotiation by
content type Content or contents may refer to: Media * Content (media), information or experience provided to audience or end-users by publishers or media producers ** Content industry, an umbrella term that encompasses companies owning and providing mas ...
and by
language Language is a structured system of communication. The structure of a language is its grammar and the free components are its vocabulary. Languages are the primary means by which humans communicate, and may be conveyed through a variety of met ...
specified in RFC 7231, there are extensions defining other aspects of content negotiation, such as ''Memento'' which describes use of a Accept-Datetime header to retrieve version of a resource's representation at particular points in timeMemento: Adding Time to the Web
Mementoweb.org. Retrieved on 2013-09-08. and the IETF/W3C's ''Content Negotiation by Profile'' which describes use of an Accept-Profile header to retrieve resource representations conforming to data profiles. Neither RFC 7231 nor the more recent related specifications such as ''Content Negotiation by Profile'' specify how to resolve trade-offs in cases where different headers specify conflicting requirements, such as, in the above example, choosing between an HTML page in English and a GIF image in German.


Agent-driven

Agent-driven or reactive content negotiation is performed by algorithms in the user-agent which choose among the possible variant representations. This is commonly performed based on a server provided list of representations and metadata about them. To summarize how this works, when a user agent submits a request to a server, the server informs the user-agent which representations it has available as well as any metadata it has about each representation (e.g., content-type, quality, language, etc.). The user-agent then resubmits the request to a specific URL for the chosen representation. This can be automatically chosen by the user-agent or the user-agent can present the user with the choices and the user can directly choose such. More precisely, the server responds with either 300 Multiple Choices or 406 Not Acceptable (when server-driven, user-agent acceptance criteria are provided but the server cannot automatically make a selection). Unfortunately HTTP leaves the format of the list of representations and metadata along with selection mechanisms unspecified.


References

{{reflist


External links

*RFC 7231 β€” ''Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content'' –
Section 5.3: Content Negotiation
*RFC 2295 β€” ''Transparent Content Negotiation in HTTP'' *RFC 2296 β€” ''HTTP Remote Variant Selection Algorithm -- RVSA/1.0''
Open source PHP content negotiation library (supports wildcards and q values)
:This article is based in part on ttp://httpd.apache.org/docs/1.3/content-negotiation.html this page which is copyrighted by the Apache Foundation but released under a free license. Hypertext Transfer Protocol